package server;

import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class MyClassLoader extends ClassLoader{

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    private String path;

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        String classPath = this.path;
        System.out.println(path);


        byte[] classBytes = null;

        Path path = null;

        try{
            path = Paths.get(new URI(classPath));
            classBytes = Files.readAllBytes(path);
            System.out.println(path);
            System.out.println(classBytes);
        }catch (Exception e){
            e.printStackTrace();
        }

        Class<?> clazz = defineClass(null, classBytes, 0, classBytes.length);

        return clazz;

    }
}
